package gjtx8;

import java.io.*;

public class Replace {
    public static void main(String[] args) {
        File f = new File("D:\\新建文件夹\\java10\\2.txt");//原文件
        File f1 = new File("D:\\新建文件夹\\java10\\chaoxian.txt");//目标文件
        try {
            BufferedReader br = new BufferedReader((new FileReader(f1)));//读取文件；
            // BufferedWriter bd=new BufferedWriter(new FileWriter(f1,true));//写入文件
            StringBuffer sb = new StringBuffer();
            int i = 0;
            String srt = null;
            while ((srt = br.readLine()) != null) {
                sb.append(srt);
            }
            i = sb.length();
            System.out.println(i);
            br.close();
            BufferedReader br1 = new BufferedReader((new FileReader(f1)));//再读取文件
            char[] b = new char[i + 10];
            int k = 0;
            k = br1.read(b);
            BufferedWriter bd = new BufferedWriter(new FileWriter(f1));//写入文件
            bd.write(new String(b, 0, k).replace("金正恩", "金三胖"));
            System.out.println();
            br1.close();
            bd.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        //String fe=f.getName();
        //f.delete();
        // f1.renameTo(f);

    }
}
